package com.you.tomcat.bio.http;

import java.io.InputStream;

/**
 * 自定义HttpRequest
 */
public class HttpRequest {

    private String url;
    private String method;

    /**
     * 接收http request请求处理
     *
     * @param in
     * @throws Exception
     */
    public HttpRequest(InputStream in) throws Exception {
        //拿到HTTP协议内容
        String content = "";
        byte[] buff = new byte[1024];
        int len = 0;
        if ((len = in.read(buff)) > 0) {
            content = new String(buff, 0, len);
        }

        String line = content.split("\\n")[0];
        String[] methodAndUrlStr = line.split("\\s");

        this.method = methodAndUrlStr[0];
        this.url = methodAndUrlStr[1].split("\\?")[0];
        System.out.println("---------接收到请求内容为：-----------");
        System.out.println(content);
    }

    public String getUrl() {
        return url;
    }

    public String getMethod() {
        return method;
    }
}
